﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace API.Core
{
    public class CommonResponse
    {
        public CommonResponse() { }

        public CommonResponse(object record)
        {
            this.Success = true;
            this.Count = 1;
            this.Data = new[] { record }.AsQueryable();
        }

        public CommonResponse(IQueryable<object> data)
        {
            this.Success = true;
            this.Count = data.Count();
            this.Data = data as IQueryable<object>;
        }

        public CommonResponse(Exception e)
        {
            this.Success = false;
            this.Message = e.Message;
        }

        public bool Success { get; set; }
        public string Message { get; set; }
        public Dictionary<string, string> RequestParameters { get; set; }
        public IQueryable<object> Data { get; set; }
        public long TotalCount { get; set; }
        public long Count { get; set; }
        public int Page { get; set; }
        public string SqlStatement { get; set; }
    }

    public class CommonErrorResponse
    {
        public CommonErrorResponse() { }

        public CommonErrorResponse(Exception e)
        {
            this.Success = false;
            this.Message = e.Message;
        }

        public bool Success { get; set; }
        public string Message { get; set; }
    }

    public class CommonSimpleResponse
    {
        public CommonSimpleResponse()
        {
            this.Success = true;
        }

        public CommonSimpleResponse(bool success, string message)
        {
            this.Success = success;
            this.Message = message;
        }

        public CommonSimpleResponse(Exception ex)
        {
            this.Success = false;
            this.Message = ex.Message;
        }

        public bool Success { get; set; }
        public string Message { get; set; }
    }

    public class CommonSimpleDataResponse
    {
        public CommonSimpleDataResponse(object obj)
        {
            this.Success = true;
            this.Data = new[] { obj };
        }

        public bool Success { get; set; }
        public string Message { get; set; }
        public IEnumerable<object> Data { get; set; }
    }
}